const axios = require('axios');
module.exports = {
    namespaced: true,
    state:{
        admlist:[],
        pageData: {
            pageSize: 4,
            currentPage: 1,
            total: 0,
            rows: []
        },
    },
    mutations:{
        getclasses(state,data){
            state.admlist = data
        },
        //改变pageData中的数组和总数
        getGoods(state, data) {
            state.pageData.total = data.total;
            state.pageData.rows = data.rows
            // console.log(state.studentsData);
        },
        //分页操作
        changepageSize(state, size) {
            state.pageData.pageSize = size;
            // console.log(state.pageData.pageSize);

        },
        changePage(state, page) {
            state.pageData.currentPage = page
            // console.log(page);

        },
    },
    actions:{
        //增加管理员
        async addadmAsync(context,name){ 
            const { data } = await axios.post("adm/addAdm",name)
            console.log( data );
        },
        //渲染管理员
        async getadmAsync(context){
            let fy = {
                pageSize: context.state.pageData.pageSize,
                currentPage: context.state.pageData.currentPage,
            }
            const { data } = await axios.get("adm/getAdm", { params: fy });
            console.log(data);
            //使用mutations函数
            context.commit('getGoods', data);
        },
        //删除管理员
        async deleteadmAsync(context,row){
            const { data } = await axios.post("adm/deleteAdm",row);
            console.log(data);
             
        },
        //修改管理员
        async updateadmAsync(context,row){
            const { data } = await axios.post("adm/updateAdm",row);
            console.log(data);
             
        }
    },
}